package com.woniuxy.carlife.carlifeuserweb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.carlife.carlifecommonsweb.exception.CarlifeGlobalException;
import com.woniuxy.carlife.carlifeuserweb.entity.ServiceInfofavorites;
import com.woniuxy.carlife.carlifeuserweb.entity.Storefavorites;
import com.woniuxy.carlife.carlifeuserweb.mapper.ServiceInfofavoritesMapper;
import com.woniuxy.carlife.carlifeuserweb.service.ServiceInfofavoritesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.carlife.carlifeuserweb.service.StatisticsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zjq
 * @ClassName:ServiceInfofavoritesServiceImpl
 * @Description:门店项目服务收藏
 * @date 2021/4/6 20:02
 **/

@Service
public class ServiceInfofavoritesServiceImpl extends ServiceImpl<ServiceInfofavoritesMapper, ServiceInfofavorites> implements ServiceInfofavoritesService {

    @Resource
    ServiceInfofavoritesMapper serviceInfofavoritesMapper;

    @Resource
    StatisticsService statisticsService;

    /*
     * 功能描述〈查询门店项目服务收藏根据用户id〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/12 14:24
     * @throws
     */

    @Override
    public List<ServiceInfofavorites> findServiceInfofavoritesByUserId(Integer userId) {
        QueryWrapper<ServiceInfofavorites> serviceInfofavoritesQueryWrapper = new QueryWrapper<>();
        serviceInfofavoritesQueryWrapper.eq("user_Id", userId);
        List<ServiceInfofavorites> serviceInfofavorites = serviceInfofavoritesMapper.selectList(serviceInfofavoritesQueryWrapper);

        return serviceInfofavorites == null ? null : serviceInfofavorites;
    }


    /*
     * 功能描述〈门店项目服务收藏收藏删除〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/14 14:51
     * @throws
     */

    @Override
    public Boolean deleteiceInfofavoritesByUserIdtServiceInfofavoritesId(Integer tServiceInfofavoritesId) {
        int i = serviceInfofavoritesMapper.deleteById(tServiceInfofavoritesId);
        return i > 0 ? true : false;
    }

    /*
     * 功能描述〈门店项目服务收藏新增〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/14 19:18
     * @throws
     */
    @Override
    public Boolean addServiceInfofavoritesByUserId(ServiceInfofavorites serviceInfofavorites) {
        int insert = serviceInfofavoritesMapper.insert(serviceInfofavorites);
        if (insert > 0) {
            boolean b = statisticsService.modifyFavorites(serviceInfofavorites.getUserId());
            if (b) {
                return true;
            }
        }
        return false;
    }

    /*
     * 功能描述〈门店项目服务数量统计根据用户id〉
     * @author:zjq
     * @param:
     * @return:
     * @Date 2021/4/15 16:11
     * @throws
     */

    @Override
    public Integer serviceInfofavoritesTotalByUserId(Integer userId) {
        QueryWrapper<ServiceInfofavorites> shoppingcartQueryWrapper = new QueryWrapper<>();
        // QueryWrapper<Employee> queryWrapper2=Wrappers.<Employee>query();
        shoppingcartQueryWrapper.eq("user_id", userId);
        Integer count = serviceInfofavoritesMapper.selectCount(shoppingcartQueryWrapper);
        return count;
    }
}
